package com.bbm.communitysystem.core.redis;

import com.bbm.communitysystem.domain.Post;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class PostRedis {

    private final RedisTemplate<String, Post> redisTemplate;

    private final String POST_KEY = "community_post:";

    @Autowired
    public PostRedis(@Qualifier("post") RedisTemplate<String, Post> redisTemplate) {
        this.redisTemplate = redisTemplate;
    }


    public void setPost(String key, Post post) {
        redisTemplate.opsForValue().set(POST_KEY + key, post);
    }


    public Post getPost(String key) {
        return redisTemplate.opsForValue().get(POST_KEY + key);
    }

    public void removePost(String key) {
        redisTemplate.delete(POST_KEY + key);
    }


}
